package com.coin.exchanges.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.coin.exchanges.view.user.bean.UserLoginBean;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.List;

import static android.content.Context.MODE_PRIVATE;

public class SpUtils {
    private static SharedPreferences sp;
    /**
     * 1.存储账本UserLoginBean的
     */
    public static void putBookBean(Context ctx, UserLoginBean bookList) {
        if (sp == null) {
            sp = ctx.getSharedPreferences("config", MODE_PRIVATE);
        }
        SharedPreferences.Editor editor = sp.edit();
        Gson gson = new Gson();
        String json = gson.toJson(bookList);
        editor.putString("login", json);
        editor.commit();
    }


    /**
     * 读取登陆的个人信息
     */
    public static UserLoginBean getBookBean(Context ctx) {
        if (sp == null) {
            sp = ctx.getSharedPreferences("config", MODE_PRIVATE);
        }
        Gson gson = new Gson();
        String json = sp.getString("login", null);

        UserLoginBean mUserLoginBean = gson.fromJson(json, UserLoginBean.class);
        return mUserLoginBean;
    }

}
